package com.kfit.config;

import java.util.Properties;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.github.pagehelper.PageHelper;

@Configuration
public class MyBatisConfiguration {

	/*
	 * @Bean public SqlSessionFactory sqlSessionFactoryBean(DataSource
	 * dataSource) throws Exception { SqlSessionFactoryBean
	 * sqlSessionFactoryBean = new SqlSessionFactoryBean();
	 * sqlSessionFactoryBean.setDataSource(dataSource);
	 * PathMatchingResourcePatternResolver resolver = new
	 * PathMatchingResourcePatternResolver();
	 * 
	 * Interceptor[] plugins = new Interceptor[]{pageHelper()};
	 * sqlSessionFactoryBean.setPlugins(plugins);
	 * 
	 * // 指定mybatisxml文件路径 sqlSessionFactoryBean.setMapperLocations(resolver
	 * .getResources("classpath:/mybatis/*.xml")); return
	 * sqlSessionFactoryBean.getObject(); }
	 */

	/**
	 * 注册MyBatis分页插件PageHelper
	 * 
	 * @return
	 */
	@Bean
	public PageHelper pageHelper() {
		System.out.println("MyBatisConfiguration.pageHelper()");
		PageHelper pageHelper = new PageHelper();
		Properties p = new Properties();
		p.setProperty("offsetAsPageNum", "true");
		p.setProperty("rowBoundsWithCount", "true");
		p.setProperty("reasonable", "true");
		pageHelper.setProperties(p);
		return pageHelper;
	}

}
